/* This reference code does not compile with the project. */

using System;
using System.Collections;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;

[SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true), AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal), SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel=true), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class RichTextField : NoteField
{
    // Fields
    private HtmlInputHidden hiddenInput;
    private bool m_bSetFocus;

    // Methods
    [SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        if ((base.ControlMode != SPControlMode.Display) && (base.Field != null))
        {
            this.hiddenInput = (HtmlInputHidden) this.TemplateContainer.FindControl("TextField_spSave");
            if (this.hiddenInput != null)
            {
                this.hiddenInput.Value = string.Empty;
            }
        }
    }

    [SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
    public override void Focus()
    {
        if (!base.InDesign)
        {
            this.m_bSetFocus = true;
        }
    }

    [SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
    protected override void OnLoad(EventArgs e)
    {
        this.EnsureChildControls();
        if ((this.Page.IsPostBack && (base.ControlMode != SPControlMode.Display)) && ((this.hiddenInput != null) && !string.IsNullOrEmpty(this.hiddenInput.Value)))
        {
            this.Text = this.hiddenInput.Value;
            this.hiddenInput.Value = string.Empty;
        }
        base.OnLoad(e);
    }

    [SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
    protected override void OnPreRender(EventArgs e)
    {
        if (this.Visible && (base.ControlMode != SPControlMode.Display))
        {
            SPUtility.RegisterRichTextOnSubmitClientScript(this.Page, base.textBox.ClientID);
        }
        if (base.RequiredFieldValidator != null)
        {
            base.RequiredFieldValidator.EnableClientScript = false;
        }
        base.OnPreRender(e);
    }

    protected override void RenderFieldForDisplay(HtmlTextWriter output)
    {
        SPFieldMultiLineText field = (SPFieldMultiLineText) base.Field;
        if (field != null)
        {
            if (field.WikiLinking && base.ItemContext.IsCurrentItemVersion)
            {
                output.Write("<div class=\"ms-wikicontent\">");
                output.Write(field.GetFieldValueAsHtml(this.ItemFieldValue, base.ListItem));
                output.Write("<p></p></div>");
                return;
            }
        }
        else
        {
            return;
        }
        base.RenderFieldForDisplay(output);
    }

    protected override void RenderFieldForInput(HtmlTextWriter output)
    {
        string direction;
        SPFieldMultiLineText field = (SPFieldMultiLineText) base.Field;
        if (field != null)
        {
            direction = null;
            if (string.IsNullOrEmpty(field.Direction) || field.Direction.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                if ((base.List != null) && !base.List.Direction.Equals("none", StringComparison.OrdinalIgnoreCase))
                {
                    direction = base.List.Direction;
                }
            }
            else
            {
                direction = field.Direction;
            }
        }
        else
        {
            return;
        }
        if (!string.IsNullOrEmpty(direction))
        {
            base.textBox.Attributes["dir"] = direction;
        }
        base.RenderFieldForInput(output);
        SPRichTextMode richTextMode = (base.Field as SPFieldMultiLineText).RichTextMode;
        string str2 = SPUtility.TextAreaToRichTextClientScript(base.textBox.ClientID, field.RestrictedMode, field.AllowHyperlink, direction, (uint) Thread.CurrentThread.CurrentUICulture.LCID, richTextMode, this.m_bSetFocus, this.Web.ServerRelativeUrl);
        output.Write(str2);
        if (field.WikiLinking)
        {
            output.Write("<span class=ms-formdescription>");
            output.Write(SPResource.GetString("WikiLinkInstructions", new object[0]));
            output.Write("</span>");
        }
    }

    [SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
    public override void Validate()
    {
        if ((base.ControlMode != SPControlMode.Display) && base.IsValid)
        {
            base.Validate();
            if (base.Field.Required && (base.Text == "<DIV></DIV>"))
            {
                base.IsValid = false;
                base.ErrorMessage = SPResource.GetString("MissingRequiredField", new object[0]);
            }
        }
    }

    // Properties
    protected override string DefaultTemplateName
    {
        get
        {
            return "RichTextField";
        }
    }

    public override string Text
    {
        set
        {
            if (!string.IsNullOrEmpty(value))
            {
                base.Text = value.Replace("\x00a0", "&nbsp;");
            }
            else
            {
                base.Text = value;
            }
        }
    }
}

 
 
